home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- * Copyright (c) 1989-1992 Stone Design Corp. All rights reserved.
- * programmer: Bill Bumgarner
- * File name: SD_BlueMarble.sl
- * Date: Jul 25 1992
- * Purpose: This is the blue_marble shader from The RenderMan
- Companion (p.355). It has been modified such that
- the colors used to define the spline across which the
- colors for the marble texture are interpolated.
- Variables:
- Ka: percentage of ambient light used
- Kd: percentage of diffuse light used
- Ks: factor of effect for the specular highlight
- roughness: roughness factor for surface; used w/highlight
- specularcolor: color used for specular highlight
-
- color1..13: colors along the spline used for interpolation
- of the marble pattern.
- ***************************************************************************/
- surface
- SD_BlueMarble(
- float Ks = .4,
- Kd = .6,
- Ka = .6,
- roughness = .1,
- txtscale = 1;
- color specularcolor = 1;
-
- color color1 = color (0.25, 0.25, 0.35), /* pale blue */
- color2 = color (0.25, 0.25, 0.35), /* pale blue */
- color3 = color (0.20, 0.20, 0.30), /* medium blue */
- color4 = color (0.20, 0.20, 0.30), /* medium blue */
- color5 = color (0.20, 0.20, 0.30), /* medium blue */
- color6 = color (0.25, 0.25, 0.35), /* pale blue */
- color7 = color (0.25, 0.25, 0.35), /* pale blue */
- color8 = color (0.15, 0.15, 0.26), /* medium dark blue */
- color9 = color (0.15, 0.15, 0.26), /* medium dark blue */
- color10 = color (0.10, 0.10, 0.20), /* dark blue */
- color11 = color (0.10, 0.10, 0.20), /* dark blue */
- color12 = color (0.25, 0.25, 0.35), /* pale blue */
- color13 = color (0.10, 0.10, 0.20); /* dark blue */
- )
- {
- point PP; /* scaled point in shader space */
- float csp; /* color spline parameter */
- point Nf; /* forward-facing normal */
- point V; /* for specular() */
- float pixelsize, twice, scale, weight, turbulence;
-
- /* Obtain a forward-facing normal for lighting calculations. */
- Nf = faceforward( normalize(N), I);
- V = normalize(-I);
-
- /*
- * Compute "turbulence" a la [PERLIN85]. Turbulence is a sum of
- * "noise" components with a "fractal" 1/f power spectrum. It gives the
- * visual impression of turbulent fluid flow (for example, as in the
- * formation of blue_marble from molten color splines!). Use the
- * surface element area in texture space to control the number of
- * noise components so that the frequency content is appropriate
- * to the scale. This prevents aliasing of the texture.
- */
- PP = transform("shader", P) * txtscale;
- pixelsize = sqrt(area(PP));
- twice = 2 * pixelsize;
- turbulence = 0;
- for (scale = 1; scale > twice; scale /= 2)
- turbulence += scale * noise(PP/scale);
-
- /* Gradual fade out of highest-frequency component near limit */
- if (scale > pixelsize) {
- weight = (scale / pixelsize) - 1;
- weight = clamp(weight, 0, 1);
- turbulence += weight * scale * noise(PP/scale);
- }
-
- /*
- * Magnify the upper part of the turbulence range 0.75:1
- * to fill the range 0:1 and use it as the parameter of
- * a color spline through various shades of blue.
- */
- csp = clamp(4 * turbulence - 3, 0, 1);
- Ci = color spline(csp, color1, color2, color3, color4, color5, color6,
- color7, color8, color9, color10, color11,
- color12, color13);
-
- /* Multiply this color by the diffusely reflected light. */
- Ci *= Ka*ambient() + Kd*diffuse(Nf);
-
- /* Adjust for opacity. */
- Oi = Os;
- Ci = Ci * Oi;
-
- /* Add in specular highlights. */
- Ci += specularcolor * Ks * specular(Nf,V,roughness);
- }
-